{{if false}}<script>{{/if}}
{{$controller = $smarty.const.CCTRL}}
{{$token = $smarty.const.TOKEN}}
{{include file="../00_base/_function.tpl"}}
function handleEvents(){
    try{
        acolumns['_id'].cellsrenderer = function (row, column, value) {
            return "<span class='a lh24 pl8' title='"+value+"'>" + value.substring(0, 10).toUpperCase() + "</span>";
        }
        acolumns['_value'].validation= function (cell, value) {
            if (value < 0 || value > 100) {
                return { result: false, message: "Position should be in the 0-100 interval" };
            }
            return true;
        };
        acolumns['_value'].createeditor=function (row, cellvalue, editor) {
            editor.jqxNumberInput({ decimalDigits: 0 });
        };
        myGrid.bind('cellendedit', function (event) {
            try{
                var args = event.args;
                var _column = args.datafield ,_row = args.rowindex,_value = args.value;
                var _data=myGrid.jqxGrid('getrowdata', _row);
                var _id=_data._id;
                if(_id==undefined || _id==""){
                    return;
                }
                switch(_column){
                    case "_status":
                        updateCol(_column,_id,_value);
                        break;
                    case "_name":
                        if(_value!=_data._name)updateCol(_column,_id,_value);
                        break;
                    case "_value":
                        if(_value!=_data._value)updateCol(_column,_id,_value);
                        break;
                    default:
                    uiMessage("Unkown this cell. Maybe 'editable' of this colums is 'off'."); 
                }
            }catch(e){
                uiMessage(e.message);
                console.log("Error:"+e.message);
            }
        });
    }catch(e){uiMessage(e.message);}
}
function SaveItem(){
    try{
        if(isrunning)return;
        console.log("Save ↵ Call");
        var _id,_name,_alias,_value,_des;                                
        _id = $('#_id').val();
        _name = $('#_name').val();
        _alias = $('#_alias').val();
        _value = $('#_value').val();
        _des = $('#_description').val();//areaContent.instanceById('txtContent').getContent();//
        var url="{{base_url()}}backend/{{$controller}}/save/{{$type}}";
        var data={
            _id             :   _id,
            _name           :   _name,
            _alias          :   _alias,
            _value          :   _value,
            _des            :   _des
        }
        //ShowNoticeDialogMessage($("<div />").text(Content).html());return;
        console.log(data);
        isrunning=true;
        myAjax(url,data,function(data){
            isrunning=false;
            if(data.result>=0){
                uiMessage(data.message)
                myjqxGrid.CancelEdit();
                myjqxGrid.Refresh();
            }else{
                ShowErrorDialogMessage(data.message);
            }
        });
    }catch(e){
        console.log("JSON Error:"+e.message+"\n↵ Error");
        ShowErrorDialogMessage(e.message);
        //ShowErrorDialogMessage("Sorry. Your request could not be completed.<br/> Please check your input data.");
    }
}